package com.huyanqi.front.rest.service.impl;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.huyanqi.core.Page;
import com.huyanqi.core.RetdCodeType;
import com.huyanqi.core.RetdObj;
import com.huyanqi.core.service.impl.BaseFrontServiceImpl;
import com.huyanqi.dao.FriendsDAO;
import com.huyanqi.entity.Friends;
import com.huyanqi.front.rest.service.FriendsRestService;

@Service("FriendsRestService")
public class FriendsRestImpl extends BaseFrontServiceImpl<Friends,Long, FriendsDAO> implements FriendsRestService{

	@Override
	@Resource(name="FriendsDAO")
	public void setEntityDao(FriendsDAO entityDao) {
		this.entityDao=entityDao;
	}
	
	@Override
	public RetdObj<List<Friends>> findMyFriends(Long uid,Integer pageNum,Integer pageSize) {
		RetdObj<List<Friends>> retd = new RetdObj<List<Friends>>();
		Page<Friends> page = new Page<Friends>();
		page.setFirstResult((pageNum-1)*pageSize);
		page.setPageSize(pageSize);
		try {
			page = entityDao.findPage(page, "SELECT new Friends(f.fuId,f.uId,f.fId,u) FROM Friends f,User u WHERE f.fId = u.uId AND f.uId = ?", uid);
			List<Friends> list = page.getResult(); 
			if(list.size()>0){
				retd.setRealObj(list);
				retd.setCode(RetdCodeType.PASS_OK);
			}else{
				retd.setCode(RetdCodeType.PASS_NODATA);
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		return retd;
	}

}
